﻿/*
* 改变输入框的样式
*/
function inputChangeColor(id) {
    $("#" + id).blur(function () {
        $(this).removeClass("inpred").addClass("inp");
    }).focus(function () {
        $(this).removeClass("inp").addClass("inpred");
    });
}
/*
* 检测邮箱地址是否正确
* return： 0表示为空 1表示大于32位 2表示不符合邮箱规则 3表示验证格式无误
*/
function checkEmail(email) {
    if (!email) {
        return 0;
    } else {
        if (email.length >= 32) {
            return 1;
        } else {
            var pattern = /^[\w\-\.]+@[\w\-]+(\.\w+)+$/;
            var flag = pattern.test(email);
            if (flag) {
                return 2;
            } else {
                return 3;
            }
        }
    }
}
/*
* 检测昵称
*/
function checkNickname(nickname) {
    if (!nickname) {
        return 0;
    }
    var len = checkChineseLen(nickname);
    if (len < 32) {
        return 1;
    } else {
        return 2;
    }
}
/*
* 检测密码
*/
function checkPwd(e) {
    var pwd = e.val();
    var len = pwd.length;
    if (!pwd) {
        return 0;
    } else {
        if (len < 6 || len > 16) {
            return -1;
        } else {
            return 1;
        }
    }
}
/*
* 验证码
*/
function changIdentifyCode() {
    var url = $('#authcode_img').attr('src');
    //var url = $("#<%=authcode_img.ClientID %>").attr('src');
    var pos_url = url.lastIndexOf('/');
    var base_url = url.substring(0, pos_url);
    $('#authcode_img').attr('src', base_url + "/Auth.aspx?code=" + Math.random());
    return false;
}
//返回强度级别
function checkStrong(sPW) {
    if (sPW.length < 6 || sPW.length > 16) {
        return 0;
    } else if (/^[a-zA-Z]+$/.test(sPW) || /^[0-9]+$/.test(sPW)) {
        if (sPW.length == 6) {
            return 1;
        } else {
            return 2;
        }
    } else if (sPW.length >= 6 && sPW.length < 10) {
        return 2;
    } else {
        return 3;
    }
}
//改变输入框默认值的字体颜色
function changeFontColor(id, val, style) {
    if ($('#' + id).val() == val) {
        if (style == 'input') {
            $('#' + id).addClass('inp_default');
        } else {
            $('#' + id).css('color', '#CACACA');
        }
    } else {
        $('#' + id).css('color', '#000');
    }
}
function checkChineseLen(str) {
    var reg = /^[\u4e00-\u9fa5]+$/;
    var len = 0;
    if (reg.test(str)) {
        len = str.length * 3;
    } else {
        len = str.length;
    }
    return len;
}
function changeAuthcode() {
    var a = document.getElementById('authcode_img');
    window.open(document.getElementById('authcode_img').src, 'authcode_img', a.src);
}

//清楚文本框数据
function cleanText() {
    //$("#userName").val('');
    $('#identity').val('');
    $("#txt_PhoneNo").val('');
    $("#txtViceFarm").val('');
    $("#txtFeeder").val('');
    $("#txtAddress").val('');
    //$("#password1").val('');
    //$("#password2").val('');
    //$("#email").val('');
    //$("#userName").focus();
}

function postRedirect(registCheck) {
    var postUrl = $('#MainContent_hidden').val();
    if (registCheck) {
        if (postUrl != null && postUrl != '') {
            var registSpan = "<span id='regstat'>注册成功</span>";
            $("#regist_msg > span").remove();
            $("#regist_msg").append(registSpan);
            var count = postUrl.lastIndexOf('/');
            var pageName = postUrl.substring(count + 1, postUrl.length);
            if (pageName.toLowerCase() == "Register.aspx".toLowerCase() || pageName.toLowerCase() == "Login.aspx".toLowerCase()) {
                window.location.href = "../Default.aspx";
            } else {
                window.location.href = postUrl;
            }
        }
        window.location.href = "../Default.aspx";
    }
}


function generateMsg(message, classType) {
    if (message != '') {
        $("#tips_message").html("");
        var div = '<div id="tips_message" class="' + classType + '"> '
                    + '<a href="#" class="close">'
                        + '<img src="../images/icons/cross_grey_small.png" title="Close this notification" alt="close" />'
                    + '</a>'
                     + '<div>' + message + '</div>'
                + '</div>';
        $("#tips_message").replaceWith(div);
    }
}

//根据QueryString参数名称获取值
function getQueryStringByName(name, href) {
    var result = href.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return result[1];
}
